<%namespace name="tw" module="tw.core.mako_util"/>\
<%
    error = context.get('error')
%>\
<fieldset ${tw.attrs(
    [('id', context.get('id')),
     ('class', css_class)],
    attrs=attrs
)}>
    % if tw.content(legend):
      <legend>${tw.content(legend)}</legend>
    % endif
    % if error and show_error:
    <div class="fielderror">${tw.content(error)}</div>
    % endif
    % if hidden_fields:
    <div>
        % for field in hidden_fields:
            <%
                error = error_for(field)
            %>
            ${field.display(value_for(field), **args_for(field))}
            % if show_children_errors and error and not field.show_error:
            <span class="fielderror">${tw.content(error)}</span>
            % endif
        % endfor
    </div>
    % endif
      <div ${tw.attrs([('id', "%s_div_wrapper" % context.get('id')), 
                       ('class', 'fieldset_fields_wrapper'),
                       ])}>
        % for i, field in enumerate(fields):
            <%
                required = ['',' required'][int(field.is_required)]
                error = error_for(field)
                label_text = field.label_text
                help_text = field.help_text
            %>
            % if show_labels and label_text and not field.suppress_label:
            <label ${tw.attrs(
                [('id', '%s_label' % field.id),
                 ('for', field.id),
                 ('class', 'fieldlabel%s' % required)]
            )}>${tw.content(label_text)}</label>
            % endif
            <div class="fieldwrapper">
              ${field.display(value_for(field), **args_for(field))}
            </div>
            % if help_text:
            <span class="fieldhelp">${tw.content(help_text)}</span>
            % endif
            <span class="feedback">
            % if show_children_errors and error and not field.show_error:
              <label class="error" for="${field.id}">${tw.content(error)}</label>
            % endif
            </span>
        % endfor
      </div>
</fieldset>\
